#specify cross compile prefix
CROSS_COMPLIE=

AS   = $(CROSS_COMPLIE)as
LD   = $(CROSS_COMPLIE)ld
CC   = $(CROSS_COMPLIE)gcc
CPP  = $(CROSS_COMPLIE)g++
AR   = $(CROSS_COMPLIE)ar
NM   = $(CROSS_COMPLIE)nm

STRIP    = $(CROSS_COMPLIE)strip
OBJDUMP  = $(CROSS_COMPLIE)objdump
OBJCOPY  = $(CROSS_COMPLIE)objcopy

#export these for sub make
export AS LD CC CPP AR NM
export STRIP OBJDUMP OBJCOPY

TOPDIR := $(shell pwd)
SRCDIR := $(TOPDIR)/src
#complier paramaters
CFLAGS     := -Wall -O2 -g -std=c99  -D_GNU_SOURCE
CFLAGS     += -I$(SRCDIR)/cjson -I$(SRCDIR)/sdk
LDFLAGS    := -lm -lpthread

#export for sub make
export CFLAGS LDFLAGS

export TOPDIR

STAMP=$(shell date +%Y%m%d%H%M)

TARGET := smartgw3rdsdk
export TARGET


liba +=$(SRCDIR)/sdk/built-in.a 


all:
	make -C ./src -f ${TOPDIR}/script/Makefile.build
	make -C ./src -f ${TOPDIR}/script/MakefileAR.build
	$(CC)  -o $(TARGET) src/built-in.o  $(liba)  $(LDFLAGS) 


clean:
	rm -f $(shell find -name "*.o")
	rm -f $(TARGET)

distclean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(shell find -name "*.a")
	rm -f $(shell find -name "*.out")
	rm -f $(shell find -name "*.gz")
	rm -f $(TARGET)


dist:
	-mkdir ~/$(STAMP)
	cp ./* ~/$(STAMP) -p -r
	tar zcvfP $(TARGET)-$(STAMP).tar.gz ~/$(STAMP)
	rm ~/$(STAMP) -rf





